package classes.web;

import org.junit.Test;

import java.io.*;
import java.net.*;

public class UDPSender {
    @Test
    public void test() {
        DatagramSocket socket = null;
        try {
            socket = new DatagramSocket();
            byte[] by = "hello world".getBytes();
            DatagramPacket dp = new DatagramPacket(by, 0, by.length, InetAddress.getByName("localhost"), 9999);  //打包的地址也要有
            socket.send(dp);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (socket != null) {
                socket.close();
            }
        }
    }
}
